package com.example.zwgt.yrfk.ui.main.activity;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.blankj.utilcode.util.ToastUtils;
import com.example.zwgt.yrfk.R;
import com.example.zwgt.yrfk.base.mvpbase.baseImpl.BaseActivity;
import com.example.zwgt.yrfk.bean.LoginResponseInfo;
import com.example.zwgt.yrfk.ui.main.MainActivity;
import com.example.zwgt.yrfk.bean.TestBean;
import com.example.zwgt.yrfk.ui.main.contact.LoginContact;
import com.example.zwgt.yrfk.ui.main.presenter.LoginPresenter;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

import butterknife.BindView;
import butterknife.OnClick;

/*
 * 项目名:    BaseFrame
 * 包名       com.zhon.frame.mvp.login.activity
 * 文件名:    LoginActivity
 * 创建者:    ZJB
 * 创建时间:  2017/9/7 on 11:21
 * 描述:     TODO 测试Activity
 */
public class LoginActivity extends BaseActivity<LoginContact.presenter> implements LoginContact.view {


    @BindView(R.id.username)
    EditText username;
    @BindView(R.id.password)
    EditText password;
    @BindView(R.id.login)
    Button login;
    private String muser;
    private String mpwd;

      public static void startAction(Activity activity){
        Intent intent = new Intent(activity, LoginActivity.class);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.fade_in,
                R.anim.fade_out);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_test;
    }


    @Override
    protected void initViews() {
    }

    /**
     * 初始化presenter
     * @return 对应的presenter
     */
    @Override
    public LoginContact.presenter initPresenter() {
        return new LoginPresenter(this);
    }




    @Override
    public void getLoadData(TestBean testBean) {
        Log.e("Data", testBean.toString());
        MainActivity.startAction(LoginActivity.this);
        //ToastUtils.showLong("登录成功");
        Toast.makeText(this,"登录成功",Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public String getUserName() {
        return username.getText().toString().trim()==null?"":username.getText().toString().trim();
    }

    @Override
    public String getPsd() {
        return password.getText().toString().trim()==null?"":password.getText().toString().trim();
    }


    @OnClick({R.id.login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //登录按钮
            case R.id.login:
                signIn();
                presenter.login();
                break;
        }
    }

    private void signIn() {
        //muser=username.getText().toString().trim();
        //mpwd=password.getText().toString().trim();
/*        if (muser.isEmpty() || mpwd.isEmpty()) {
            return;
        }*/
        EMClient.getInstance().login("ttt", "ttt", new EMCallBack() {
            @Override
            public void onSuccess() {
                EMClient.getInstance().groupManager().loadAllGroups();
                EMClient.getInstance().chatManager().loadAllConversations();
                Toast.makeText(LoginActivity.this,muser+mpwd+"sp登录成功",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(final int i, final String s) {

            }

            @Override
            public void onProgress(int i, String s) {
            }
        });
    }

}
